package com.woniu.microprojectserver.buildclassmag.controller;

import com.woniu.microcommonsserver.entity.BuildClassInfoEntity;
import com.woniu.microcommonsserver.param.ResponseMsg;
import com.woniu.microprojectserver.buildclassmag.service.impl.BuildClassServiceImpl;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/buildClass")
public class BuildClassController {

    @Resource
    private BuildClassServiceImpl buildClassService;

    @GetMapping(value = "/findAll",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg findAll(){
        List<BuildClassInfoEntity> lists = buildClassService.findAll();
        return ResponseMsg.builder().code(200).msg("查询成功").data(lists).build();
    }

    @GetMapping(value = "/findByName",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg findByName(String name){
        List<BuildClassInfoEntity> lists = buildClassService.findByName(name);
        return ResponseMsg.builder().code(200).msg("查询成功").data(lists).build();
    }

    @PostMapping(value = "/add",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg add(@RequestBody BuildClassInfoEntity buildClassInfoEntity){
        boolean b = buildClassService.add(buildClassInfoEntity);
        return ResponseMsg.builder().code(200).msg("添加成功").data(b).build();
    }

    @PostMapping(value = "/update",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg update(@RequestBody BuildClassInfoEntity buildClassInfoEntity){
        boolean b = buildClassService.update(buildClassInfoEntity);
        return ResponseMsg.builder().code(200).msg("修改成功").data(b).build();
    }

}
